package com.demo.security.web;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description
 * @author: fanxl
 * @date: 2018/12/10 0010 17:03
 */
@RequestMapping("test")
@RestController
public class TestController {

    @GetMapping
    public String test() {
        return "ok";
    }

    @GetMapping("me")
    public String me() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return "ok";
    }

    @GetMapping("other")
    public Authentication other(Authentication authentication) {
        return authentication;
    }

    @GetMapping("else-me")
    public UserDetails elseMe(@AuthenticationPrincipal UserDetails userDetails) {
        return userDetails;
    }
}
